/*******************************************************************************
 * @file    bsp_watchdog.c
 * @brief   Device watchdog interface.
 *
 * @version 1.0.0
 *******************************************************************************
 * @license Refer License or other description Docs
 * @author  Felix
 ******************************************************************************/
#include "cpu/bsp_watchdog.h"
#include "wdt.h"

/****
Global Functions
****/

/**
 * @brief Initialize watchdog
 */
void BSP_WatchdogInit(uint32_t secs)
{
    en_wdt_time_t wov = WdtT1s64; /* 1.6s */

    if(secs <= 0){
        return;
    }

    if(secs > 1){
        wov++;
    }

    if(secs > 3){
        wov++;
    }

    if(secs > 6){
        wov++;
    }

    if(secs > 13){
        wov++;
    }

    if(secs > 26){
        wov++;
    }

    Sysctrl_SetPeripheralGate(SysctrlPeripheralWdt,TRUE);

    Wdt_Init(WdtResetEn, wov);
    Wdt_Start();
}

/**
 * @brief  execute a watchdog feeding
 */
void BSP_WatchdogFeed(void)
{
    Wdt_Feed();
}
